<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');
	class Admin_User_Model extends CI_Model {
		function __construct(){
			parent::__construct();
		}
		
		function get_user_data($order_by, $sort_ord){
			if($order_by == 'first_name'){
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/users_ctrl/first_name_sort/';
			}else{
				$base_url = 'http://localhost/azindia/azindia-client/index.php/admin/users_ctrl/index/';
			}
			if($this->uri->segment(4)){
				$current_page = $this->uri->segment(4);
			}else{
				$current_page = 0;
			}			
			$per_page = 2;
			
			$url = 'http://localhost/azindia/azindia-api/json.api';
			$data = array('www-command'=>'adminuser-all_adminusers','current_page'=>$current_page,'results_per_page'=>$per_page, 'sort_order'=>$sort_ord, 'order_by'=>$order_by);
			$string = http_build_query($data);
			//echo '<pre>';print_r($data);exit;
			$ch = curl_init($url);
			curl_setopt($ch,CURLOPT_POST,true);
			curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
			$response = json_decode(curl_exec($ch));
			//echo '<pre>';print_r($response);exit;
			curl_close($ch);
			
			$this->load->library('pagination');			
			$config['base_url'] = $base_url;
			$config['per_page'] = $per_page;
			$config['total_rows']  = $response->total;
			$config['uri_segment'] = 4;
			$config['num_links'] = 1;
			$config['prev_link'] = 'Previous';
			$config['next_link'] = 'Next';
			$config['first_link'] = 'First';
			$config['last_link'] = 'Last';
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
			$data['adminuser_all_adminuser'] = $response;
			//echo '<pre>';print_r($response);exit;
			$this->load->view('admin/users_view',$data);
			
		}
		
		function user_data($data){
			$url = "http://localhost/azindia/azindia-api/json.api";
			$string = http_build_query($data);
			//echo '<pre>';print_r($data);exit;
			$ch = curl_init($url);
			curl_setopt($ch,CURLOPT_POST,true);
			curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
			curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
			$response = json_decode(curl_exec($ch));
			//echo '<pre>';print_r($response);exit;
			curl_close($ch);
			return $response;
		}
	}